package com.dmgis.hndz.service.impl;

import cn.hutool.core.util.IdUtil;
import com.dmgis.hndz.common.utils.StringUtil;
import com.dmgis.hndz.common.utils.SysResult;
import com.dmgis.hndz.mapper.SendUnitManagementMapper;
import com.dmgis.hndz.pojo.SendUnitManagement;
import com.dmgis.hndz.service.SendUnitManagementService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author pengdongdong
 * @description public
 * @date 2024-11-05
 */
@Service
public class SendUnitManagementServiceImpl implements SendUnitManagementService {

    @Resource
    private SendUnitManagementMapper sendUnitManagementMapper;

    /**
     * 新增
     *
     * @author pengdongdong
     * @date 2025-01-10
     **/
    public SysResult insertSendUnitManagement(SendUnitManagement sendUnitManagement) {
        // 查询是否已有发送单位
        String unitName = sendUnitManagementMapper.selectUnitNameByCode(sendUnitManagement.getCode());
        if (!StringUtil.IsNullOrEmpty(unitName)){
            return SysResult.fail("已有单位名称！");
        }
        Date date = new Date();
        sendUnitManagement.setId(IdUtil.simpleUUID());
        sendUnitManagement.setCreateTime(date);
        sendUnitManagement.setUpdateTime(date);
        sendUnitManagementMapper.insertSendUnitManagement(sendUnitManagement);
        return SysResult.success("添加成功！");
    }

    /**
     * 更新
     *
     * @author pengdongdong
     * @date 2025-01-10
     **/
    public SysResult updateSendUnitManagement(SendUnitManagement sendUnitManagement) {
        sendUnitManagement.setUpdateTime(new Date());
        sendUnitManagementMapper.updateSendUnitManagement(sendUnitManagement);
        return SysResult.success("修改成功！");
    }

}